package com.hfmall.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hfmall.entity.HfManager;
import com.hfmall.entity.ResponseCode;
import com.hfmall.service.impl.HfManagerServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2021-08-11
 */
@CrossOrigin
@RestController
@RequestMapping("/manager")
public class HfManagerController {

    @Autowired
    HfManagerServiceImpl hfManagerService;

    @PostMapping("login")
    public ResponseCode login(@RequestBody HfManager manager, HttpServletResponse response) {
        QueryWrapper<HfManager> wrapper = new QueryWrapper<>();
        wrapper.eq("account", manager.getAccount());
        HfManager user = hfManagerService.getOne(wrapper);

        if (user == null) {
            return new ResponseCode(401, "账号不存在");
        } else if (user.getPassword().equals(manager.getPassword())) {
            return ResponseCode.SUCCESS;
        } else {
            return new ResponseCode(402, "密码不正确");
        }

    }
}
